/*
 * Trida pro zobrazovani v okne, pracuje s SVG, prozatim zvlada zakladni fuknce
 * tzn. obraz centruje, dovoluje zoom pomoci SeekBar, pri zoomu jde s obrazem pohybovat
 * a hlida hranice aby se obraz nedostal mimo zobrazeni displaye
 * 
 * Dalsi postup: 	zjistit jestli dokaze centrovat skutecne mapy a urcovat hranice
 * 					!!!zjistit jak zvetsit ten SeekBar protoze pracovat s nim je o nervy!!!
 * 					nebo zoomovat dlouhym dotykem a SeekBar vyhodit
 * 				
 * Problemy:		pri rychlem "odzoomovani" se obraz dostava mimo zobrazeni, ale 
 * 					dotykem se zpetne vycentruje
 */


package android.svgview;

import java.util.Observable;
import java.util.Observer;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ZoomControls;

public class SVGView extends ImageView implements Observer {
	
	private TextView zoomView;
	private ViewState viewState;
	private Paint paint = new Paint();
	
	public SVGView(Context context, AttributeSet attrs) {
		super(context, attrs);
		paint.setColor(Color.BLACK);
	}

	public void setViewState(ViewState viewState){
		if(this.viewState==null){
			this.viewState = viewState;
			this.viewState.addObserver(this);
		}
	}
	
	public void setZoomTextView(TextView textView){
		if(zoomView==null){
			zoomView = textView;
		}
	}
	
	protected void onDraw(Canvas canvas){

		try{
			
			viewState.setViewSize(getWidth(), getHeight());
			/* !!! pri velky zmene zoomu smerem dolu se obraz dostava mimo hranici okna, 
			vystredi se az po dotyku - az budou realny mapy, OPRAVIT !!!*/
			canvas.scale(viewState.getZoom(), viewState.getZoom());
			canvas.translate(viewState.getX(), viewState.getY());
			zoomView.setText("ZOOM "+(int)viewState.getZoom()+"X");
		}
		catch(NullPointerException e){
			e.printStackTrace();
			//potom dommyslet, zatim jen aby nehlasil NullPointerEception XML Layout
		}
		//podle umisteni je svg obraz v popredi ci (aktualne) v pozadi 
		super.onDraw(canvas);
		
		//oramovani obrazku - zatim pro kontrolu, potom vymazat!!!
		canvas.drawLine(0, 0, getWidth(), 0, paint);
		canvas.drawLine(0, 0, 0, getHeight(), paint);
		canvas.drawLine(0, getHeight(),getWidth(),getHeight(), paint);
		canvas.drawLine(getWidth(),0,getWidth(),getHeight(), paint);
		canvas.drawLine(getWidth()/2, 0, getWidth()/2, getHeight(), paint);
		//
		
		
	}
	public void update(Observable observable, Object data) {
		invalidate();
		
	}
	
}


